﻿
Ext.namespace('LanWatch');
Ext.namespace('LanWatch.Grids');

Ext.define('LanWatch.Grids.GridPanelBaseCls', {
    extend: 'Ext.grid.Panel',

    //Default Properties:
    autoWidth: true,    
    autoScroll: true,
    bodyBorder: false,
    border: false,
    closable: false,
    enableColumnResize: true,
    enableColumnMove: true,
    viewConfig: { stripRows: true, forceFit: false },

    //Private Properties:
    _innerStore: {},
    _gridSelModel: {},

    //initComponent:-------------------------------------------------------------------------------------------
    initComponent: function () {
        
        this.callParent();

        var storeModel = Ext.ModelManager.getModel(this.store.model);
        this._innerStore = Ext.create('Ext.data.Store', {
            model: storeModel
        });

        this._gridSelModel = this.getSelectionModel();

        this.wireEvents();
    }, //End of initComponent.

    //onSelect:------------------------------------------------------------------------------------------------
    onSelect: function (rowModel, record, index, eOpts) {

        this._innerStore.add(record);
        //console.log(this._innerStore.count());
    }, //End of onSelect.

    //onSelectionChanged:--------------------------------------------------------------------------------------
    onSelectionChanged: function (model, selectedItems, eOpts) {
    }, //End of onSelectionChanged.

    //onDeselect:----------------------------------------------------------------------------------------------
    onDeselect: function (rowModel, record, index, eOpts) {
        this._innerStore.remove(record);
    }, //End of onDeselect.

    //onDblClick:----------------------------------------------------------------------------------------------
    onDblClick: function (view, record, itemHtmlEl, index, e, eOpts) {

        this._gridSelModel.deselect([record]);
        this.onDeselect(null, record, index, eOpts);
    }, //End of onDblClick.

    //getSelected:---------------------------------------------------------------------------------------------
    getSelected: function () {

        var count = this._innerStore.count();
        var records = new Array();

        for (var i = 0; i < count; i++) {
            var record = this._innerStore.getAt(i);
            records.push(record);
        }
        return records;
    }, //End of getSelected.

    //clearSelected:-------------------------------------------------------------------------------------------
    clearSelected: function () {

        this._gridSelModel.deselectAll();
        this._innerStore.removeAll();
    }, //End of clearSelected.

    //wireEvents:----------------------------------------------------------------------------------------------
    wireEvents: function () {
        this.on('select', this.onSelect, this);
        this.on('itemdblclick', this.onDblClick, this);
        this.on('deselect', this.onDeselect, this);
    } //End of wireEvents.
});